require('../models/workspace.js');
var _ = require('lodash');
var mongoose  = require('mongoose');
var Workspace = mongoose.model('Workspace');

exports.addWorkspace = function(work_info,callback){
    var workspace = new Workspace(work_info);
    workspace.save(callback);
};
exports.updateMembers = function(work_id,members,callback){
    Workspace.update({_id:work_id},{
        user:members
    }, callback);
};
exports.getWorkspaceByName = function (work_name, callback) {
    Workspace.find({'work_name': work_name}, callback);
};

exports.getWorkspaceById = function (work_id, callback) {
    Workspace.findOne({ _id: work_id}, callback);
};

exports.getWorkspaces = function (project_id,callback) {
    Workspace.find({project_id:project_id},callback);
};

exports.getAllWorkspaces = function (callback) {
    Workspace.find({},callback);
};

exports.updateDependency = function(work_id,dependency_info,callback){
    Workspace.update({_id:work_id},{
        dependencies:dependency_info
    }, callback);
};

exports.deleteWorkspace = function(work_id,callback){
    Workspace.remove({ _id: work_id}, callback);
}

exports.getWorkspacesByProjects = function(project_ids,callback){
    Workspace.find({project_id: {$in: project_ids}}, callback);
}
